!(function () {
    var Globaldata = [
        {
            qnum:32,
            qdata:[
                {
                    sort:"0",
                    remain:"31",
                    progress:"3.125",
                    type:"2",
                    question:"你和你的配偶(男/女朋友)在一场争吵后和解了",
                    answers:[
                        {val:"0", title:"我原谅了他"},
                        {val:"1", title:"我通常是个宽宏大量的人"}
                    ]
                },
                {
                    sort:"1",
                    remain:"30",
                    progress:"6.25",
                    type:"1",
                    question:"你忘掉了配偶的生日",
                    answers:[
                        {val:"0", title:"我不擅长记生日"},
                        {val:"1", title:"我太忙了"}
                    ]
                },
                {
                    sort:"2",
                    remain:"29",
                    progress:"9.375",
                    type:"4",
                    question:"有人匿名送你一束鲜花",
                    answers:[
                        {val:"0", title:"是因为我很有吸引力"},
                        {val:"1", title:"是因为我人缘好"}
                    ]
                },
                {
                    sort:"3",
                    remain:"28",
                    progress:"12.5",
                    type:"4",
                    question:"你竞选一个职位而且当选了",
                    answers:[
                        {val:"0", title:"我花了很多时间和精力在竞选上"},
                        {val:"1", title:"我对每一件事都会全力以赴"}
                    ]
                },
                {
                    sort:"4",
                    remain:"27",
                    progress:"15.625",
                    type:"3",
                    question:"你忘记了一个重要的约会",
                    answers:[
                        {val:"1", title:"有时我的记性不好"},
                        {val:"0", title:"有时我忘了检查我的记事本"}
                    ]
                },
                {
                    sort:"5",
                    remain:"26",
                    progress:"18.75",
                    type:"2",
                    question:"你的晚宴很成功",
                    answers:[
                        {val:"0", title:"我那天晚上特别的迷人"},
                        {val:"1", title:"我是个很好的主人"}
                    ]
                },
                {
                    sort:"6",
                    remain:"25",
                    progress:"21.875",
                    type:"1",
                    question:"你欠图书馆10元罚款,因为你借的书逾期了",
                    answers:[
                        {val:"1", title:"我看得太入迷，忘记该什么时候还"},
                        {val:"0", title:"我忙着写报告，忘记去还书"}
                    ]
                },
                {
                    sort:"7",
                    remain:"24",
                    progress:"25",
                    type:"2",
                    question:"你的股票帮你赚了很多钱",
                    answers:[
                        {val:"0", title:"我的经纪人决定冒险试试新股票"},
                        {val:"1", title:"我的经纪人是一流的投资人才"}
                    ]
                },
                {
                    sort:"8",
                    remain:"23",
                    progress:"28.125",
                    type:"2",
                    question:"你赢得了一项运动比赛",
                    answers:[
                        {val:"0", title:"我所向无敌"},
                        {val:"1", title:"我训练很刻苦"}
                    ]
                },
                {
                    sort:"9",
                    remain:"22",
                    progress:"31.25",
                    type:"3",
                    question:"你未通过一个重要的考试",
                    answers:[
                        {val:"1", title:"我不够聪明,比不上其他同学"},
                        {val:"0", title:"我没有好好为这次考试做准备"}
                    ]
                },
                {
                    sort:"10",
                    remain:"21",
                    progress:"34.375",
                    type:"3",
                    question:"你特地为朋友准备了一道菜，但他连碰都没碰",
                    answers:[
                        {val:"1", title:"我不是个好厨师"},
                        {val:"0", title:"我今天准备得太匆忙了"}
                    ]
                },
                {
                    sort:"11",
                    remain:"20",
                    progress:"37.5",
                    type:"3",
                    question:"你输掉了一场准备已久的比赛",
                    answers:[
                        {val:"1", title:"我不是一个优秀的运动员"},
                        {val:"0", title:"我不擅长那项运动"}
                    ]
                },
                {
                    sort:"12",
                    remain:"19",
                    progress:"40.625",
                    type:"1",
                    question:"你对朋友发了脾气",
                    answers:[
                        {val:"1", title:"他老是烦我"},
                        {val:"0", title:"他今天情绪不好"}
                    ]
                },
                {
                    sort:"13",
                    remain:"18",
                    progress:"43.75",
                    type:"1",
                    question:"你因未及时缴纳个人所得税而被罚款",
                    answers:[
                        {val:"1", title:"我总是拖延报税"},
                        {val:"0", title:"我今年太懒了"}
                    ]
                },
                {
                    sort:"14",
                    remain:"17",
                    progress:"46.875",
                    type:"3",
                    question:"你想与某人约会，但他拒绝你了",
                    answers:[
                        {val:"1", title:"我那天受到了沉重的打击"},
                        {val:"0", title:"我去约他时，紧张得说不出话来"}
                    ]
                },
                {
                    sort:"15",
                    remain:"16",
                    progress:"50",
                    type:"2",
                    question:"在聚会时常有人邀你跳舞",
                    answers:[
                        {val:"1", title:"在聚会上，我很擅长交际"},
                        {val:"0", title:"那晚我表现得很完美"}
                    ]
                },
                {
                    sort:"16",
                    remain:"15",
                    progress:"53.125",
                    type:"2",
                    question:"你在面试时表现良好",
                    answers:[
                        {val:"0", title:"面试时我很自信"},
                        {val:"1", title:"我很会面试"}
                    ]
                },
                {
                    sort:"17",
                    remain:"14",
                    progress:"56.25",
                    type:"4",
                    question:"你的老板没有给你足够的时间去完成那项工作,不过你还是按时完工了",
                    answers:[
                        {val:"0", title:"我对我的工作很在行"},
                        {val:"1", title:"我是个很有效率的人"}
                    ]
                },
                {
                    sort:"18",
                    remain:"13",
                    progress:"59.375",
                    type:"1",
                    question:"你最近感到精疲力竭",
                    answers:[
                        {val:"1", title:"我从来就没有休息的机会"},
                        {val:"0", title:"这个星期我实在太忙了"}
                    ]
                },
                {
                    sort:"19",
                    remain:"12",
                    progress:"62.5",
                    type:"4",
                    question:"你救了一个差点噎死的人",
                    answers:[
                        {val:"0", title:"我会这种急救技巧"},
                        {val:"1", title:"我知道在危机时该如何处理"}
                    ]
                },
                {
                    sort:"20",
                    remain:"11",
                    progress:"65.625",
                    type:"3",
                    question:"你的男/女朋友想暂时冷却一阵子你们的感情",
                    answers:[
                        {val:"1", title:"我太自我中心了"},
                        {val:"0", title:"我冷落了他,没有花很多时间在他身上"}
                    ]
                },
                {
                    sort:"21",
                    remain:"10",
                    progress:"68.75",
                    type:"1",
                    question:"朋友的一句话伤了我的心",
                    answers:[
                        {val:"1", title:"他每次都是这样脱口而出,不考虑对方的感受"},
                        {val:"0", title:"朋友今天心情不好,拿我撒气呢"}
                    ]
                },
                {
                    sort:"22",
                    remain:"9",
                    progress:"71.875",
                    type:"4",
                    question:"你的老板向你寻求忠告",
                    answers:[
                        {val:"0", title:"我是这个领域的专家"},
                        {val:"1", title:"我很会提出有用的建议"}
                    ]
                },
                {
                    sort:"23",
                    remain:"8",
                    progress:"75",
                    type:"4",
                    question:"你的朋友感谢你帮助他度过了一段困难的时光",
                    answers:[
                        {val:"0", title:"我喜欢帮助人度过难关"},
                        {val:"1", title:"我关心别人"}
                    ]
                },
                {
                    sort:"24",
                    remain:"7",
                    progress:"78.125",
                    type:"4",
                    question:"你的医生告诉你,你的身体状况很好",
                    answers:[
                        {val:"0", title:"我经常运动"},
                        {val:"1", title:"我非常在意健康"}
                    ]
                },
                {
                    sort:"25",
                    remain:"6",
                    progress:"81.25",
                    type:"2",
                    question:"你的配偶(男/女朋友)带你去度了一个浪漫的周末",
                    answers:[
                        {val:"0", title:"他需要休息几天"},
                        {val:"1", title:"他喜欢去探索新的地方"}
                    ]
                },
                {
                    sort:"26",
                    remain:"5",
                    progress:"84.375",
                    type:"2",
                    question:"你被请去主持一个重要项目",
                    answers:[
                        {val:"0", title:"我最近刚完成一个类似的项目"},
                        {val:"1", title:"我是一个很好的项目主管"}
                    ]
                },
                {
                    sort:"27",
                    remain:"4",
                    progress:"87.5",
                    type:"1",
                    question:"你滑雪时常摔跤",
                    answers:[
                        {val:"1", title:"滑雪是项很难的运动"},
                        {val:"0", title:"滑雪道上有冰"}
                    ]
                },
                {
                    sort:"28",
                    remain:"3",
                    progress:"90.625",
                    type:"4",
                    question:"你赢得了一项很有声望的奖项",
                    answers:[
                        {val:"0", title:"我解决了一个重要的问题"},
                        {val:"1", title:"我是最好的员工"}
                    ]
                },
                {
                    sort:"29",
                    remain:"2",
                    progress:"93.75",
                    type:"3",
                    question:"你的股票跌到不能再低",
                    answers:[
                        {val:"1", title:"我那时不了解股市行情"},
                        {val:"0", title:"我选错了股票"}
                    ]
                },
                {
                    sort:"30",
                    remain:"1",
                    progress:"96.875",
                    type:"1",
                    question:"你放假时胖了，现在瘦不下来了",
                    answers:[
                        {val:"1", title:"从长远来说,节食其实没什么用"},
                        {val:"0", title:"我试的这个节食法没有用"}
                    ]
                },
                {
                    sort:"31",
                    remain:"0",
                    progress:"100",
                    type:"3",
                    question:"商店不收你的信用卡",
                    answers:[
                        {val:"1", title:"我有时高估了我的钱数"},
                        {val:"0", title:"我有时忘了付信用卡账单"}
                    ]
                }
            ]
        },
        {
            qnum:10,
            qdata:[
                {
                    sort:"0",
                    remain:"9",
                    progress:"10",
                    type:"1",
                    question:"我是一个情绪平稳的人",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                },
                {
                    sort:"1",
                    remain:"8",
                    progress:"20",
                    type:"1",
                    question:"我对自己很满意",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                },
                {
                    sort:"2",
                    remain:"7",
                    progress:"30",
                    type:"1",
                    question:"我感到焦虑和紧张",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                },
                {
                    sort:"3",
                    remain:"6",
                    progress:"40",
                    type:"1",
                    question:"我希望自己能像别人认为的那样快乐",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                },
                {
                    sort:"4",
                    remain:"5",
                    progress:"50",
                    type:"1",
                    question:"我觉得自己是个失败者",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                },
                {
                    sort:"5",
                    remain:"4",
                    progress:"60",
                    type:"1",
                    question:"每当我反思最近的得失时,我都会焦虑不安",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                },
                {
                    sort:"6",
                    remain:"3",
                    progress:"70",
                    type:"1",
                    question:"我很有安全感",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                },
                {
                    sort:"7",
                    remain:"2",
                    progress:"80",
                    type:"1",
                    question:"我信心满满",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                },
                {
                    sort:"8",
                    remain:"1",
                    progress:"90",
                    type:"1",
                    question:"我觉得自己能力不足",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                },
                {
                    sort:"9",
                    remain:"0",
                    progress:"100",
                    type:"1",
                    question:"我会杞人忧天",
                    answers:[
                        {val:"4", title:"几乎不是"},
                        {val:"3", title:"有时如此"},
                        {val:"2", title:"常如此"},
                        {val:"1", title:"一直如此"}
                    ]
                }
            ]
        },
        {
            qnum:16,
            qdata:[
                {
                    sort:"0",
                    remain:"15",
                    progress:"6.25",
                    type:"3",
                    question:"我的生活是为了一个更加高尚的目的",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"1",
                    remain:"14",
                    progress:"12.5",
                    type:"1",
                    question:"生命如此短暂,没有时间把享受它所能带来的快乐放在次要地位",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"2",
                    remain:"13",
                    progress:"18.75",
                    type:"2",
                    question:"我总是想要寻找那种能够挑战我能力的环境",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"3",
                    remain:"12",
                    progress:"25",
                    type:"4",
                    question:"我给自已的生活打分",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"4",
                    remain:"11",
                    progress:"31.25",
                    type:"2",
                    question:"无论是在工作还是在玩,我总是深陷其中,甚至觉察不到自我",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"5",
                    remain:"10",
                    progress:"37.5",
                    type:"2",
                    question:"我总是沉浸在我所做的事情当中",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"6",
                    remain:"9",
                    progress:"43.75",
                    type:"2",
                    question:"我很少被周围发生的事情所干扰",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"7",
                    remain:"8",
                    progress:"50",
                    type:"3",
                    question:"我有责任让世界变得更美好 ",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"8",
                    remain:"7",
                    progress:"56.25",
                    type:"3",
                    question:"我的生活是有最终意义的",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"9",
                    remain:"6",
                    progress:"62.5",
                    type:"4",
                    question:"无论我正在做什么,赢对我都是很重要的",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"10",
                    remain:"5",
                    progress:"68.75",
                    type:"1",
                    question:"在选择做什么的时候,我总是考虑这件事情是否会让我感到快乐",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"11",
                    remain:"4",
                    progress:"75",
                    type:"3",
                    question:"我做的事情对于社会来说很重要",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"12",
                    remain:"3",
                    progress:"81.25",
                    type:"4",
                    question:"我想比别人更成功",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"13",
                    remain:"2",
                    progress:"87.5",
                    type:"1",
                    question:'我同意这句话:“生活是短暂的,所以想吃什么就吃什么!"',
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"14",
                    remain:"1",
                    progress:"93.75",
                    type:"1",
                    question:"我喜欢做让我感到有刺激性的事情",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                },
                {
                    sort:"15",
                    remain:"0",
                    progress:"100",
                    type:"4",
                    question:"我喜欢竞争",
                    answers:[
                        {val:"5", title:"绝对像我"},
                        {val:"4", title:"很大程度上像我"},
                        {val:"3", title:"有些像我"},
                        {val:"2", title:"只有一点像我"},
                        {val:"1", title:"完全不像我"}
                    ]
                }
            ]
        }
    ];
    /*初始化*/
    var evapp = new Framework7({
        root : "#evapp",
        name : "优势累积",
        version : "1.0.0",
        view : {
            pushState:true
        },
        dialog:{
            buttonOk:"确认",
            buttonCancel:"取消"
        },
        routes : [
            {
                path : "/home/",
                url  : "./pages/home.html"
            },
            {
                path : "/test/:testno/",
                templateUrl  : "./pages/test.html"
            },
            {
                path : "/results/",
                url  : "./pages/results.html"
            }
        ]

    });
    var evMainView = evapp.views.create('.view-main',{});
    /*全局变量*/
    var $$ = Dom7;
    var Globaluid;
    var Globaltestno,Globalcurrentq,Globalqnum,Globalans;

    var qitemTemplate = $$('script#Qitem').html();
    var compiledQitemTemplate = Template7.compile(qitemTemplate);
    var testItemTemplate = $$('script#Testitem').html();
    var compiledTestItemTemplate = Template7.compile(testItemTemplate);
    var resultItemTemplate = $$('script#Resultitem').html();
    var compiledResultItemTemplate = Template7.compile(resultItemTemplate);
    /*页面事件*/
    $$(document).on('page:init','.page[data-name="Home"]',function () {
        //console.log('page home init');
        getfinishstatus();
    });
    $$(document).on('page:init','.page[data-name="Test"]',function () {
        //console.log('page test init');
        Globaltestno = $$('.page[data-name="Test"]').data('test');
        Globalcurrentq = 0;
        Globalqnum = Globaldata[Globaltestno]['qnum'];
        Globalans = {};

        loadnextq();
    });
    $$(document).on('page:init','.page[data-name="Results"]',function () {
        //console.log('page results init');
        getresults();
    });
    $$(document).on('click','.nextq-btn',function () {
        if (Globalcurrentq < Globalqnum-1) {
            //保存答案
            var data = evapp.form.convertToData('#ansform');
            if (data.qans===undefined) {evapp.dialog.alert('请选择您的答案','');return;}
            //console.log(data);
            Globalans[Globalcurrentq] = {ans:data.qans,type:data.qtype};
            Globalcurrentq++;
            //载入下一题
            if (Globalcurrentq < Globalqnum) {
                loadnextq();
                //设定progress
                evapp.progressbar.set('.progressbar', Globaldata[Globaltestno]['qdata'][Globalcurrentq]['progress']);
                if (Globalcurrentq === Globalqnum - 1) {
                    $$('.page[data-name="Test"] .nextq-btn span').html('提交问卷');
                }
            }
        }else {
            var data = evapp.form.convertToData('#ansform');
            if (data.qans===undefined) {evapp.dialog.alert('请选择您的答案','');return;}
            //console.log(data);
            Globalans[Globalcurrentq] = {ans:data.qans,type:data.qtype};
            submit();
        }
    });
    $$(document).on('click','.show-results-btn',function () {
        evMainView.router.navigate('/results/');
    });
    /*工具函数*/
    function checklogin() {
        //console.log('checklogin');
        evapp.request({
            async:false,
            method:'GET',
            url:"http://api.nldou.com/evaluation/checklogin",
            data:{},
            dataType:'json',
            xhrFields:{"withCredentials":true},
            success:function (res) {
                //console.log(res);
                if (res.code==1){
                    if (res.data.status == 1) {
                        loginscreen();
                    }else{
                        Globaluid = res.data.uid;
                        kp.stop();
                        evMainView.router.navigate('/home/',{reloadCurrent:true});
                    }
                }else{
                    //session不存在
                    window.location.href='http://api.nldou.com/ucenter/weixinlogin?pid=2539';
                }
            }
        })
    }
    function loginscreen() {
        //console.log('loginscreen');
        evapp.dialog.prompt(
            "请输入您的姓名","",function(name){
                name = name.replace(/(^\s*)|(\s*$)/g, "");
                if (!name) {
                    evapp.dialog.alert("输入的姓名不能为空","",loginscreen);
                    return;
                }
                evapp.request({
                    async:false,
                    method:'POST',
                    url:"http://api.nldou.com/evaluation/firstlogin",
                    data:{name:name},
                    dataType:'json',
                    xhrFields:{"withCredentials":true},
                    success:function(res){
                        //console.log(res);
                        if (res.code==1){
                            Globaluid = res.data.uid;
                            kp.stop();
                            evMainView.router.navigate('/home/',{reloadCurrent:true});
                        }else{
                            //session不存在
                            window.location.href='http://api.nldou.com/ucenter/weixinlogin?pid=2539';
                        }
                    }
                })
            }
        )
    }
    function initwxsdk(){
        evapp.request({
            url:"http://api.nldou.com/weixinapi/init_wx_jsapi",
            method:"GET",
            data: {fromUrl:window.location.href},
            dataType:'json',
            success: function (res) {
                if(res.code==1){
                    wx.config({
                        debug: false,
                        appId: res.data.appid,
                        timestamp: res.data.timestamp,
                        nonceStr: res.data.nonceStr,
                        signature: res.data.signature,
                        jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','hideMenuItems','chooseImage'
                            ,'uploadImage','getLocalImgData']
                    });
                }
            }
        });
        wx.ready(function () {
            wx.hideMenuItems({
                menuList: ['menuItem:share:qq', 'menuItem:share:weiboApp', 'menuItem:share:facebook', 'menuItem:share:QZone'
                    ,'menuItem:copyUrl', 'menuItem:openWithQQBrowser', 'menuItem:openWithSafari']
            });
            wx.onMenuShareTimeline({
                title: '优势累积课程测试',
                link: 'http://api.nldou.com/ucenter/weixinlogin?pid=2539',
                imgUrl: 'http://wap.nldou.com/evaluation/img/adv-logo.jpg'
            });
            wx.onMenuShareAppMessage({
                title: '优势累积课程测试',
                desc: '为保证课程效果，请认真填写',
                link: 'http://api.nldou.com/ucenter/weixinlogin?pid=2539',
                imgUrl: 'http://wap.nldou.com/evaluation/img/adv-logo.jpg',
                type: 'link'
            });
        });
    }
    function loadnextq() {
        var qsort = Globalcurrentq+1;
        $$('.page[data-name="Test"] .qsort').html(qsort);
        var remainq = Globalqnum-(Globalcurrentq+1);
        $$('.page[data-name="Test"] .qremain').html(remainq);
        var html = compiledQitemTemplate(Globaldata[Globaltestno]['qdata'][Globalcurrentq]);
        $$('.page[data-name="Test"] .answer-container').html(html);
    }
    function submit() {
        evapp.dialog.preloader('提交中');
        evapp.request.post("http://api.nldou.com/evaluation/submit",{uid:Globaluid,data:Globalans,testno:Globaltestno},function (res) {
            //console.log(res);
            if (res.code==1){
                evapp.dialog.close();
                evapp.dialog.alert('提交成功','',function () {
                    evMainView.router.navigate('/home/',{reloadCurrent:true});
                });
            }else{
                evapp.dialog.close();evapp.dialog.alert('提交失败请重试','');
            }
        },function () {evapp.dialog.close();evapp.dialog.alert('提交失败请重试','');},'json');
    }
    function getfinishstatus() {
        evapp.request.get("http://api.nldou.com/evaluation/getFinishStatus",{uid:Globaluid},function (res) {
            if (res.code==1){
                $$('.page[data-name="Home"] .complishednum').html(res.data.num);
                var html = compiledTestItemTemplate(res.data.complished);
                $$('.page[data-name="Home"] .test-list ul').html(html);
            }
        },function () {},'json');
    }
    function getresults() {
        evapp.request.get("http://api.nldou.com/evaluation/getResults",{uid:Globaluid},function (res) {
            if (res.code==1){
                //console.log(res.data);
                var html = compiledResultItemTemplate(res.data);
                $$('.page[data-name="Results"] .page-content').html(html);
            }
        },function () {},'json');
    }
    /*开屏*/
    function Loginanim(speed){
        this.delta=0;
        this.speed=speed;
        this.animid=0;
    }
    Loginanim.prototype={
        constructor:Loginanim,
        anim:function () {
            this.delta+=this.speed;
            var d0 = Math.abs(Math.sin(Math.PI/2+this.delta));
            var d1 = Math.abs(Math.sin(Math.PI/3+this.delta));
            var d2 = Math.abs(Math.sin(Math.PI/6+this.delta));
            $$('.login-anim-btn').eq(0).css({'opacity':d0});
            $$('.login-anim-btn').eq(1).css({'opacity':d1});
            $$('.login-anim-btn').eq(2).css({'opacity':d2});
            this.animid=requestAnimationFrame(this.anim.bind(this));
        },
        start:function () {
            this.animid = requestAnimationFrame(this.anim.bind(this));
        },
        stop:function () {
            cancelAnimationFrame(this.animid);
        }
    };
    /*main*/
    var kp = new Loginanim(0.03);
    kp.start();
    initwxsdk();
    checklogin();
})();